package com.eastcom.collection.timingtask


import com.eastcom.collection.tools.file.*
import org.apache.commons.logging.Log
import org.apache.commons.logging.LogFactory
import org.quartz.Job
import org.quartz.JobExecutionContext
import org.quartz.JobExecutionException
import com.eastcom.collection.provider.DynamicBeanRegisterProvider
import com.eastcom.collection.provider.*
/**
 * Created by yuanyue on 2014-07-31.
 */
class Task implements Job{
	/** 任务id */
	String jobId;

	/** 任务名称 */
	String jobName;

	/** 任务分组 */
	String jobGroup;

	/** 任务状态 0禁用 1启用 2删除*/
	String jobStatus;

	/** 任务运行时间表达式 */
	String cronExpression;

	/** 任务描述 */
	String desc;
	
	boolean cached;
	
	String classPath
	
	private static Log logger = LogFactory.getLog(Task.class)
	
	Object doWork() {
		Thread.currentThread().setName(jobId)
		GroovyObject classObj = GroovyUtil.loadScriptObject(classPath, true)
		println classObj
		Object o = classObj.invokeMethod("doJob",jobId)
		return o
	}
	@Override
	void execute(JobExecutionContext context) throws JobExecutionException {
		Task scheduleJob = (Task) context.getMergedJobDataMap().get("scheduleJob");
		try {
			scheduleJob.doWork()
		}catch (Exception e){
			logger.error(this, e);
		}
	}
}
